#!usr/bin/node

const jsdom = require("jsdom");
const {JSDOM} = jsdom;

const htmlFileName = process.argv[2];
const htmlFIlePath = __dirname+"/"+htmlFileName;
const fs = require("fs");

try{
  const data = fs.readFileSync(htmlFIlePath,"utf-8");
  const dom = new JSDOM(data);

  let divNode = dom.window.document.querySelector(".con");
  let content = dom.window.document.querySelector(".con").textContent;
  let pNode = dom.window.document.createElement("p");
  let pContent = dom.window.document.createTextNode(content);

  pNode.appendChild(pContent);

  pNode.setAttribute("class","list");

  dom.window.document.querySelector("body").replaceChild(pNode,divNode);
  
  console.log(dom.window.document.querySelector("html").outerHTML);
  fs.writeFileSync(__dirname+"/a.html","");

}catch(err) {
  console.error(err);
}
